package Servidor.Controlador;

import Servidor.Modelo.Games.GameList;
import Servidor.Modelo.Principal_Nueva_Partida_Ventana;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;

/**
 *
 * @author Jorge
 */
class StartGameTask extends Thread implements OcaTask {

    PrintWriter write;
    BufferedReader read;
    Socket socket;
    int idGame;

    public StartGameTask(Socket socket, BufferedReader read, PrintWriter write) {
        this.write = write;
        this.socket = socket;
        this.read = read;
    }

    @Override
    public void executeTask() {
        this.start();
    }

    @Override
    public void run() {
        String idGameString = null;

        try {
            idGameString = read.readLine();
        } catch (IOException ex) {
            System.out.println("No se pudo leer la id partida para unirse");
        }

        try {
            idGame = Integer.parseInt(idGameString);
        } catch (NumberFormatException ex) {
            System.out.println("La id partida para unirse no es valida");
        }
        
        
        
        GameList.getInstance().getGame(idGame).start_game();
        
        
        /*Principal_Nueva_Partida_Ventana vista = new Principal_Nueva_Partida_Ventana(GameList.getInstance().getGame(idGame));
        vista.setVisible(true);
        GameList.getInstance().getGame(idGame).addObserver(vista);
        
        GameList.getInstance().getGame(idGame).start_game();*/
        
        System.out.println("Partida arrancada");
    }
}